/**
 * @overview 创建点图元扩散涟漪动画类
 * @author wangxingxing
 * @description 鲸云CgsCircleAnimation
 * @update  2022.03.23
 */

class GCircleAnimation {
  constructor() {
    window.GCircleAnimationArray = []
  }

  add(paramObj) {
    const { name, option } = paramObj
    const optionModified = {
      position: option.position,
      radius: option.radius || 10,
      fillColor: option.fillColor || 'rgba(255,0,0,0.8)',
      duration: option.duration || 2000,
      visible: option.visible || true,
    }
    const circleanimation = new CgsCircleAnimation(optionModified)
    const circleanimationObject = {
      name: name,
      circleanimation: circleanimation,
    }
    window.map.addFeature(circleanimation)
    window.GCircleAnimationArray.push(circleanimationObject)
  }

  removeAll() {
    window.GCircleAnimationArray.forEach((item) => {
      window.map.removeFeature(item.circleanimation)
    })
    window.GCircleAnimationArray = []
  }

  removeSingle(name) {
    window.GCircleAnimationArray.forEach((item, index) => {
      if (item.name == name) {
        window.GCircleAnimationArray.splice(index, 1)
        window.map.removeFeature(item.circleanimation)
      }
    })
  }

  setVisible(name, boolean) {
    window.GCircleAnimationArray.forEach((item, index) => {
      if (item.name == name) {
        item.circleanimation.setVisible(boolean)
      }
    })
  }
}

export default GCircleAnimation
